import dayjs from "dayjs";

function getcolumns(setdrawer) {
  return {
    columns: [
      {
        title: "备件名称",
        dataIndex: "name",
        key: "name",
        formItemProps: { rules: [{ required: true, message: "此项为必填项" }] },
      },
      {
        title: "备件编码",
        dataIndex: "code",
        key: "code",
        formItemProps: { rules: [{ required: true, message: "此项为必填项" }] },
      },
      {
        title: "备件类型",
        dataIndex: "spare_type_name",
        key: "spare_type_name",
        formItemProps: { rules: [{ required: true, message: "此项为必填项" }] },
      },
      {
        title: "可用库存",
        dataIndex: "can_use_stock",
        key: "can_use_stock",
        formItemProps: { rules: [{ required: true, message: "此项为必填项" }] },
        search: false,
        valueType: "digit",
      },
      {
        title: "库存",
        dataIndex: "stock",
        key: "stock",
        formItemProps: {
          rules: [{ required: false, message: "此项为必填项" }],
        },
        search: false,
        hideInForm: true,
        valueType: "digit",
        render: (text, row) => {

          return row?.spare_suppliers?.length>0? row?.spare_suppliers
            ?.map?.((it) => {
              return it?.stock;
            })
            ?.reduce?.((prev, next) => {
              return prev + next;
            }) : 0;
        },
      },
      {
        title: "单位",
        dataIndex: "unit_name",
        key: "unit_name",
        formItemProps: { rules: [{ required: true, message: "此项为必填项" }] },
        search: false,
      },
    ],
    pathconfig: {
      enableadd: true,
      enableedit: true,
      enabledelete: true,
      enabledetail: true,
      add: "/spare",
      edit: "/spare",
      list: "/spare",
      delete: "/spare",
      detail: "",
    },
  };
}
export default getcolumns;
